package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ChatGroup;
import com.ruoyi.system.service.IChatGroupService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 群组Controller
 * 
 * @author ruoyi
 * @date 2025-08-30
 */
@RestController
@RequestMapping("/system/chatGroup")
public class ChatGroupController extends BaseController
{
    @Autowired
    private IChatGroupService chatGroupService;

    /**
     * 查询群组列表
     */
    @PreAuthorize("@ss.hasPermi('system:chatGroup:list')")
    @GetMapping("/list")
    public TableDataInfo list(ChatGroup chatGroup)
    {
        startPage();
        List<ChatGroup> list = chatGroupService.selectChatGroupList(chatGroup);
        return getDataTable(list);
    }

    /**
     * 导出群组列表
     */
    @PreAuthorize("@ss.hasPermi('system:chatGroup:export')")
    @Log(title = "群组", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ChatGroup chatGroup)
    {
        List<ChatGroup> list = chatGroupService.selectChatGroupList(chatGroup);
        ExcelUtil<ChatGroup> util = new ExcelUtil<ChatGroup>(ChatGroup.class);
        util.exportExcel(response, list, "群组数据");
    }

    /**
     * 获取群组详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:chatGroup:query')")
    @GetMapping(value = "/{groupId}")
    public AjaxResult getInfo(@PathVariable("groupId") Long groupId)
    {
        return success(chatGroupService.selectChatGroupByGroupId(groupId));
    }

    /**
     * 新增群组
     */
    @PreAuthorize("@ss.hasPermi('system:chatGroup:add')")
    @Log(title = "群组", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ChatGroup chatGroup)
    {
        return toAjax(chatGroupService.insertChatGroup(chatGroup));
    }

    /**
     * 修改群组
     */
    @PreAuthorize("@ss.hasPermi('system:chatGroup:edit')")
    @Log(title = "群组", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ChatGroup chatGroup)
    {
        return toAjax(chatGroupService.updateChatGroup(chatGroup));
    }

    /**
     * 删除群组
     */
    @PreAuthorize("@ss.hasPermi('system:chatGroup:remove')")
    @Log(title = "群组", businessType = BusinessType.DELETE)
	@DeleteMapping("/{groupIds}")
    public AjaxResult remove(@PathVariable Long[] groupIds)
    {
        return toAjax(chatGroupService.deleteChatGroupByGroupIds(groupIds));
    }
}
